<template>
  <div class='search'>
    <f-form ref='form' :action='api.hyOrderDetails.calculate' :form-key='this.formItem.orderDetailsId'>
      <f-form-item label='结算价' type='number' :required='true' :precision='4' data-type='number' name='settlePrice' :value='formItem.settlePrice' :disabled='formItem.disabled'/>
      <f-form-item label='结算标准' type='number' :required='true' :precision='4' data-type='number' name='settleRate' :value='formItem.settleRate' :disabled='formItem.disabled'/>
      <f-form-item label='结算金额' type='number' :required='true' :precision='2' data-type='number' :disabled='formItem.disabled' name='settleAmount' :value='formItem.settleAmount' />
      <f-form-item label='结算公式' placeholder='请选择结算公式' name='settleFormulaContent' :readOnly='formItem.disabled' :required='true' :value.sync='formItem.settleFormulaContent' :trigger-change='true'>
        <a-tooltip slot='addonBefore' placement='top' title='点击图标选择公式'>
          <a-icon type='calculator' style='cursor:pointer' @click='openFormulaModal' />
        </a-tooltip>
      </f-form-item>
      <f-form-item label='提成单价' type='number'  :precision='4' data-type='number' name='rebateAmount' :value='formItem.rebateAmount' :disabled='formItem.disabled'/>
      <f-form-item label='提成公式' placeholder='请选择提成公式' name='rebateSettleFormula' :readOnly='formItem.disabled'  :value.sync='formItem.rebateSettleFormula' :trigger-change='true'>
        <a-tooltip slot='addonBefore' placement='top' title='点击图标选择公式'>
          <a-icon type='calculator' style='cursor:pointer' @click='openFormulaModal2' />
        </a-tooltip>
      </f-form-item>
    </f-form>
    <select-formula-modal ref='formulaModal' @onSelectChange='onSelectFormulaChange'></select-formula-modal>
    <select-formula-modal ref='formulaModal2' @onSelectChange='onSelectFormulaChange2'></select-formula-modal>
  </div>
</template>
<script>
import api from "../../js/api"
import SelectFormulaModal from "../../components/select_formula_modal"

export default {
  name: "HyOrderCalculateTab2",
  props: {},
  data() {
    return {
      refs: this.$refs,
      loadDept: false,
      api: Object.assign(api, this.api),
      isAdd: true,//是否是添加模式
      loaded: false,//是否加载完成
      formItem: this.getFormItem(),
      disabled: false,
      params1: {
        formulaType: 1
      },
      params2: {
        formulaType: 4
      },
      params3: {
        formulaType: 3
      },
      params4: {
        formulaType: 2
      }
    }
  },
  methods: {
    getFormItem() {
      return {
        orderId: "",
        orderNo: "",
        delivery: "",
        sendType: "",
        saleManName: "",
        customName: "",
        settleRate: "",
        invoiceSendType: 0,
        reputation: "",
        reputationAmount: "",
        bankId: "",
        settleType: 0,
        customBondType: 0,
        supplierBondType: 0,
        customId: "",
        billsType: "",
        remark: ""
      }
    },
    //表单赋值
    setData(data) {
      this.$refs.form.resetFields()
      this.formItem = this.getFormItem()
      if (data && data.orderDetailsId) {
        this.http.get(this, {
          url: this.api.hyOrderDetails.get,
          params: {
            orderDetailsId: data.orderDetailsId,
            handlerName: "hyCalCulateTab1GetHandler"
          },
          success: function(me, data) {
            me.formItem = data
            
          }
        })

      }
    },
    /**
     * 选择公式
     */
    openFormulaModal() {
      this.$refs["formulaModal"].open({
        formulaType: 3
      })
    },
    /**
     * 选择公式2
     */
    openFormulaModal2() {
      this.$refs["formulaModal2"].open({
        formulaType: 3
      })
    },
    /**
     * 公式选择回调
     */
    onSelectFormulaChange(selectedRowKeys, selectedRows) {
      this.$refs.form.getForm().setFieldsValue({ "settleFormulaContent": selectedRows[0].formulaContent })
      this.formItem.settleFormulaContent= selectedRows[0].formulaContent;
    },
    /**
     * 公式选择回调
     */
    onSelectFormulaChange2(selectedRowKeys, selectedRows) {
      this.$refs.form.getForm().setFieldsValue({ "rebateSettleFormula": selectedRows[0].formulaContent })
      this.formItem.rebateSettleFormula= selectedRows[0].formulaContent;
    },
    //提交表单
    handleSubmit(callback) {
      this.$refs.form.submit({ orderDetailsId: this.formItem.orderDetailsId }, callback)
    }
  },
  mounted() {

  },
  created() {
  },
  components: { SelectFormulaModal }
}
</script>

<style scoped lang='less' rel='stylesheet/less'>

</style>
